<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>管理员 - 贷款管理</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
</head>
<body>
    <div class="container">
        <h1 class="mt-4">贷款管理</h1>
        
        <div class="d-flex justify-content-between mb-4">
            <h2>所有贷款</h2>
            <a href="${pageContext.request.contextPath}/admin/loan" class="btn btn-primary">待审批贷款</a>
        </div>
        
        <table class="table table-striped mt-4">
            <thead>
                <tr>
                    <th>贷款ID</th>
                    <th>贷款编号</th>
                    <th>申请人</th>
                    <th>金额</th>
                    <th>剩余金额</th>
                    <th>申请时间</th>
                    <th>到期时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${loans}" var="loan">
                    <tr>
                        <td>${loan.id}</td>
                        <td>${loan.loanNumber}</td>
                        <td>${loan.user.realName}</td>
                        <td>${loan.amount}</td>
                        <td>${loan.remainingAmount}</td>
                        <td>${loan.createTime}</td>
                        <td>${loan.dueDate}</td>
                        <td>
                            <c:choose>
                                <c:when test="${loan.status == 1}">待审批</c:when>
                                <c:when test="${loan.status == 2}">已批准</c:when>
                                <c:when test="${loan.status == 3}">已还清</c:when>
                                <c:otherwise>已拒绝</c:otherwise>
                            </c:choose>
                        </td>
                        <td>
                            <button type="button" class="btn btn-info view-details" data-loan-id="${loan.id}">查看详情</button>
                        </td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        $(document).ready(function() {
            // 查看详情按钮点击事件
            $('.view-details').click(function() {
                var loanId = $(this).data('loan-id');
                // 这里可以添加查看详情的逻辑
                alert('查看贷款ID为' + loanId + '的详情');
            });
        });
    </script>
</body>
</html>